﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Data;
namespace LHWebApp.Json
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class JsonGetToiletInfoList : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string op = context.Request.Params["op"];
            switch (op)
            {
                case "GetMenuJobFeedback"://菜单 反馈记录
                    GetMenuJobFeedback(context);
                    break;
                case "GetMenuTemporaryMission"://菜单 临时任务
                    GetMenuTemporaryMission(context);
                    break;
                case "GetMenuSetCleanerList"://菜单 作业公厕设定-人员作业公厕设置
                    GetMenuSetCleanerList(context);
                    break;
                case "GetMenuSetCleanerListDoubleClick"://菜单 作业公厕设定-人员作业公厕设置 双击
                    GetMenuSetCleanerListDoubleClick(context);
                    break;
                case "GetMenuSetToiletList"://菜单 作业公厕设定-公厕作业公厕查询
                    GetMenuSetToiletList(context);
                    break;
                case "GetMenuCleanerList"://菜单 人员管理列表
                    GetMenuCleanerList(context);
                    break;
                case "GetMenuCleanerTeam"://cmb 人员组织机构
                    GetMenuCleanerTeam(context);
                    break;
                case "GetToiletInfo"://实时在线统计 公厕实时监控统计
                    GetToiletInfo(context);
                    break;
                case "GetMenuAttendanceInfoDay"://菜单 考勤管理-考勤记录(日)
                    GetMenuAttendanceInfoDay(context);
                    break;
                case "GetMenuAttendanceInfoMonth"://菜单 考勤管理-考勤记录（月）
                    GetMenuAttendanceInfoMonth(context);
                    break;
                case "GetMenuToiletWorkInfo"://菜单 考勤管理-公厕作业
                    GetMenuToiletWorkInfo(context);
                    break;
                default:
                    context.Response.Write("{success: noFindOP}");
                    break;
            }
        }

        private string stringDATACut(string dataString)
        {

            string[] sArray = dataString.Split('T');
            //最后结果为  sArray[0]=abcABC; sArray[1]=err; sArray[2]=sss
            return sArray[0];
        }
        //菜单 考勤管理-考勤记录（日）
        private void GetMenuAttendanceInfoDay(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string date = stringDATACut(context.Request.Params["date"]);
            string statue = context.Request.Params["statue"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuAttendanceInfoDay(clientNo, date, statue);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;

                string statusString = "上午迟到:" + ds.Tables[1].Rows[1][1].ToString() + " | 上午早退:" + ds.Tables[1].Rows[3][1].ToString() + " |下午迟到: " + ds.Tables[1].Rows[2][1].ToString() + " | 下午早退:" + ds.Tables[1].Rows[4][1].ToString() + " | 正常:" + ds.Tables[1].Rows[0][1].ToString() + " |缺卡: " + ds.Tables[1].Rows[5][1].ToString();
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        //姓名	清运队	班组	作业范围	上午签入	上午签出	下午签入	下午签出
                        jsonHelp.AddItem("name", dr[0].ToString());
                        jsonHelp.AddItem("clientName", dr[1].ToString());
                        jsonHelp.AddItem("wcName", dr[2].ToString());
                        jsonHelp.AddItem("amIN", dr[4].ToString());
                        jsonHelp.AddItem("amOUT", dr[5].ToString());
                        jsonHelp.AddItem("pmIN", dr[6].ToString());
                        jsonHelp.AddItem("pmOUT", dr[7].ToString());

                        jsonHelp.AddItem("statusString", statusString);
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //菜单 考勤管理-考勤记录（月）
        private void GetMenuAttendanceInfoMonth(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string date = context.Request.Params["date"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuAttendanceInfoMonth(clientNo, date);
                DataTable dt = ds.Tables[0];
                
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;

                //0正常
                //1上午迟到
                //2下午迟到
                //3上午早退
                //4下午早退
                //5缺卡
                string statusString = "正常率:" + ds.Tables[1].Rows[0][1].ToString() + " | 迟到率:" + ds.Tables[1].Rows[1][1].ToString() + " |早退率: " + ds.Tables[1].Rows[2][1].ToString();

                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {

//                        姓名	所属分组	负责公厕	正常	迟到	早退	上班未打卡	下班未打卡	缺勤	VID


                        jsonHelp.AddItem("name", dr[0].ToString());
                        jsonHelp.AddItem("clientName", dr[1].ToString());
                        jsonHelp.AddItem("wcName", dr[2].ToString());
                        jsonHelp.AddItem("normal", dr[3].ToString());
                        jsonHelp.AddItem("late", dr[4].ToString());
                        jsonHelp.AddItem("LeaveEarly", dr[5].ToString());
                        jsonHelp.AddItem("comeNoC", dr[6].ToString());
                        jsonHelp.AddItem("leaveNoC", dr[7].ToString());
                        jsonHelp.AddItem("queS", dr[8].ToString());
                        jsonHelp.AddItem("VID", dr[9].ToString());

                        jsonHelp.AddItem("statusString", statusString);
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //菜单 考勤管理-公厕作业
        private void GetMenuToiletWorkInfo(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string date = context.Request.Params["date"];
            string name = context.Request.Params["name"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuToiletWorkInfo(clientNo, date, name);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        jsonHelp.AddItem("name", dr[0].ToString());
                        jsonHelp.AddItem("time", dr["ORIENTATION_TIME"].ToString());
                        jsonHelp.AddItem("toiletName", dr[2].ToString());
                        jsonHelp.AddItem("sex", dr["SEX"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }
        
        //菜单 反馈记录
        private void GetMenuJobFeedback(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string date1 = context.Request.Params["date1"];
            string date2 = context.Request.Params["date2"];
            string wcName = context.Request.Params["wcName"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuJobFeedback(clientNo,date1, date2, wcName);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        jsonHelp.AddItem("clientNo", dr["CLIENT_NO"].ToString());
                        jsonHelp.AddItem("time", dr["ORIENTATION_TIME"].ToString());
                        jsonHelp.AddItem("roadName", dr["ROADNAME"].ToString());
                        jsonHelp.AddItem("location", dr["LOCATION"].ToString());
                        jsonHelp.AddItem("detail", dr["DETAIL"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //菜单 临时任务
        private void GetMenuTemporaryMission(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string date = context.Request.Params["date"];
            string name = context.Request.Params["name"];
            string status = context.Request.Params["status"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuTemporaryMission(clientNo, date, name, status);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        //下发时间0	任务时间1	任务道路2	任务地点3	任务要求4	负责班组5	任务状态6
                        jsonHelp.AddItem("missionDate", dr[1].ToString());
                        jsonHelp.AddItem("missionToilet", dr[3].ToString());
                        jsonHelp.AddItem("missionAD", dr[2].ToString());
                        jsonHelp.AddItem("clientName", dr[5].ToString());
                        jsonHelp.AddItem("missionStatus", dr[6].ToString());
                        jsonHelp.AddItem("missionAsk", dr[4].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //菜单 作业公厕设定-人员作业人员设置
        private void GetMenuSetCleanerList(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuSetCleanerList(clientNo);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        //序号	姓名	所属分组	维保公厕	维保开始时间	维保结束时间	设置时间
                        jsonHelp.AddItem("vid", dr["序号"].ToString());
                        jsonHelp.AddItem("name", dr["姓名"].ToString());
                        jsonHelp.AddItem("clientName", dr["所属分组"].ToString());
                        jsonHelp.AddItem("ToiletName", dr["维保公厕"].ToString());
                        jsonHelp.AddItem("startDate", dr["维保开始时间"].ToString());
                        jsonHelp.AddItem("endDate", dr["维保结束时间"].ToString());
                        jsonHelp.AddItem("settingDate", dr["设置时间"].ToString());

                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }
        
        //菜单 作业公厕设定-人员作业人员设置 双击
        private void GetMenuSetCleanerListDoubleClick(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string cleanerName = context.Request.Params["cleanerName"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuSetCleanerListDoubleClick(cleanerName);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        //序号	姓名	所属分组	维保公厕	维保开始时间	维保结束时间	设置时间
                        jsonHelp.AddItem("vid", dr[0].ToString());
                        jsonHelp.AddItem("id", dr[1].ToString());
                        jsonHelp.AddItem("name", dr[2].ToString());
                        jsonHelp.AddItem("startTime", dr[3].ToString());
                        jsonHelp.AddItem("endTime", dr[4].ToString());
                        jsonHelp.AddItem("createDate", dr[5].ToString());
                        jsonHelp.AddItem("level", dr[6].ToString());
                        jsonHelp.AddItem("workCount", dr[7].ToString());
                 
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //菜单 作业公厕设定-公厕作业公厕查询
        private void GetMenuSetToiletList(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuSetToiletList(clientNo);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        //序号	公厕名称	所属分组	负责维保人员（按维保时间先后顺序排列）

                        jsonHelp.AddItem("vid", dr["序号"].ToString());
                        jsonHelp.AddItem("ToiletName", dr["公厕名称"].ToString());
                        jsonHelp.AddItem("clientName", dr["所属分组"].ToString());
                        jsonHelp.AddItem("peopleNames", dr["负责维保人员（按维保时间先后顺序排列）"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //菜单 人员管理列表
        private void GetMenuCleanerList(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string name = context.Request.Params["name"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuCleanerList(clientNo, name);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {

                        jsonHelp.AddItem("vid", dr["VID"].ToString());
                        jsonHelp.AddItem("name", dr["NAME"].ToString());
                        jsonHelp.AddItem("simNO", dr["SIMCARD_NO"].ToString());
                        jsonHelp.AddItem("clientNO", dr["CLIENT_NO"].ToString());
                        jsonHelp.AddItem("sex", dr["SEX"].ToString());
                        jsonHelp.AddItem("phone", dr["PHONE"].ToString());
                        jsonHelp.AddItem("worktype", dr["WORKTYPE"].ToString());
                        jsonHelp.AddItem("birthDay", dr["BIRTHDAY"].ToString());
                        jsonHelp.AddItem("workDay", dr["WORKDATE"].ToString());

                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //cmb 人员组织机构
        private void GetMenuCleanerTeam(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuCleanerTeam(clientNo);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {

                        jsonHelp.AddItem("CLIENT_NO", dr["CLIENT_NO"].ToString());
                        jsonHelp.AddItem("CLIENT_NAME", dr["CLIENT_NAME"].ToString());
                        //jsonHelp.AddItem("PARENT_NO", dr["PARENT_NO"].ToString());
                        //jsonHelp.AddItem("CREATE_DATE", dr["CREATE_DATE"].ToString());
                        //jsonHelp.AddItem("COLOUR", dr["COLOUR"].ToString());
                        //jsonHelp.AddItem("DATEDIFF", dr["DATEDIFF"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //实时在线统计 公厕实时监控统计
        private void GetToiletInfo(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];

            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetToiletInfo(clientNo);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr[0].ToString() == "公厕名称")
                        {
                            continue;
                        }
                        jsonHelp.AddItem("LicensePlate", dr[0].ToString());
                        jsonHelp.AddItem("Location", dr[1].ToString());
                        jsonHelp.AddItem("section3", dr[2].ToString());
                        jsonHelp.AddItem("CarType", dr[3].ToString());
                        jsonHelp.AddItem("section5", dr[4].ToString());
                        jsonHelp.AddItem("section6", dr[5].ToString());
                        jsonHelp.AddItem("section7", dr[6].ToString());
                        jsonHelp.AddItem("section8", dr[7].ToString());
                        jsonHelp.AddItem("section9", dr[8].ToString());
                        jsonHelp.AddItem("section10", dr[9].ToString());
                        jsonHelp.AddItem("Lng", dr[10].ToString());
                        jsonHelp.AddItem("Lat", dr[11].ToString());
                        jsonHelp.AddItem("section13", dr[12].ToString());
                        jsonHelp.AddItem("section14", dr[13].ToString());
                        jsonHelp.AddItem("section15", dr[14].ToString());

                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

